<template>
	<view>
		<htz-signature @sumbit="sumbit" @fail="fail" cid="ceshi1"></htz-signature>
	</view>
</template>

<script>
	import {
		baseUrl
	} from "@/api/api.js"
	import htzSignature from '@/components/htz-signature/htz-signature.vue'
	import {
		deliveryUserSign
	} from "@/api/user.js"
	export default {
		data() {
			return {
				fileId: 0,
				captcha: "",
				baseUrl: "",
				platform: 1
			}
		},
		components: {
			htzSignature,
		},
		onLoad(option) {
			// #ifdef APP-PLUS
			plus.screen.unlockOrientation();
			plus.screen.lockOrientation('landscape-primary');
			// #endif
			this.baseUrl = baseUrl()
			this.fileId = option.fileId
			this.captcha = option.captcha
		},
		methods: {
			sumbit(res) {
				uni.showLoading({
					mask: true,
					title: "上传中..."
				})
				let tempFilePath = res.tempFilePath
				//#ifdef APP-PLUS
				let token = uni.getStorageSync("Authori-zation");
				this.platform = 2
				let _this = this
				uni.uploadFile({
					// 需要上传的地址
					url: _this.baseUrl + "/upload/image",
					header: {
						"Authori-zation": "Bearer " + token
					},
					// filePath  需要上传的文件
					filePath: tempFilePath,
					name: "file",
					success(_res) {
						uni.hideLoading()
						uni.showLoading({
							mask: true,
							title: "签署中..."
						})
						var res = JSON.parse(_res.data);
						if (_res.statusCode === 200 && res.status === 200) {
							tempFilePath = res.data.url
							_this.doDeliveryUserSign(tempFilePath)
						} else {
							uni.showToast({
								title: "上传失败"
							});
						}
					}
				});
				//#endif
				//#ifdef H5
				this.doDeliveryUserSign(tempFilePath)
				//#endif
			},
			fail(err) {
				console.log('fail', err)
			},
			doDeliveryUserSign(src) {
				deliveryUserSign({
					fileId: this.fileId,
					sealData: src,
					platform: this.platform,
					code: this.captcha
				}).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						duration: 600
					})
					setTimeout(function() {
						uni.navigateBack({

						})
					}, 650)
				})
			}
		},
		onUnload() {
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary');
			// #endif
		}
	}
</script>

<style>

</style>
